package com.example.icedcap.topeka_fake.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.icedcap.topeka_fake.R;
import com.example.icedcap.topeka_fake.model.Avatar;
import com.example.icedcap.topeka_fake.widget.AvatarView;

/**
 * Created by doushuqi on 15-7-11上午10:53.
 * Email:doushuqi0409@gmail.com
 */
public class AvatarAdapter extends BaseAdapter {
    private final LayoutInflater mInflater;
    private static final Avatar[] sAvatars = Avatar.values();

    public AvatarAdapter(Context c) {
        mInflater = LayoutInflater.from(c);
    }

    @Override
    public int getCount() {
        return sAvatars.length;
    }

    @Override
    public Object getItem(int position) {
        return sAvatars[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.item_avatar, parent, false);
            setAvatar((AvatarView)convertView, sAvatars[position]);
        }
        return convertView;
    }

    private void setAvatar(AvatarView v, Avatar avatar) {
        v.setImageResource(avatar.getDrawableResId());
        v.setContentDescription(avatar.getNameForAccessibility());
    }
}
